package org.telegram.bot.mapper;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.common.enums.StatusEnum;
import org.telegram.bot.domain.BotKeyWordReply;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 关键词回复Mapper接口
 *
 * @author wyx
 * @date 2024-11-24
 */
public interface BotKeyWordReplyMapper extends BaseMapper<BotKeyWordReply>
{

    /**
     * 查询关键词回复列表
     *
     * @param botKeyWordReply 关键词回复
     * @return 关键词回复集合
     */
    public List<BotKeyWordReply> selectBotKeyWordReplyList(BotKeyWordReply botKeyWordReply);
    
    /**
     * 关键字与回复配置映射
     * @param chatId
     * @return
     */
    default Map<String, String> getKeyReplyMap(Long chatId){
        Map<String,String> map = new HashMap<>();
        List<BotKeyWordReply> botKeyWordReplies = selectList(new LambdaQueryWrapper<BotKeyWordReply>().eq(BotKeyWordReply::getStatus, StatusEnum.OK.getCode()).eq(BotKeyWordReply::getChatId, chatId));
        for (BotKeyWordReply botKeyWordReply : botKeyWordReplies) {
            List<String> list = StrUtil.splitTrim(botKeyWordReply.getKeyWord(), ",");
            for (String key : list) {
                map.put(key,botKeyWordReply.getConfig());
            }
        }
        return map;
    }
}
